package org.hgf.testrabbitmq.controller;

import org.hgf.testrabbitmq.domain.MqConfig;
import org.hgf.testrabbitmq.producer.service.IRabbitMqProducerService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author 何国发
 * @version 1.0.0
 * @date 2022/9/9 15:24
 */
@RestController
@RequestMapping("/test")
public class TestController {

    @Resource
    private RabbitTemplate rabbitTemplate;

    @Resource
    private IRabbitMqProducerService producerService;

    @PostMapping("/sendMsg")
    public String sendMsg(@RequestBody MqConfig mqConfig)
    {
        producerService.createQueueIfNotExist(mqConfig);
        rabbitTemplate.convertAndSend(mqConfig.getRouteKey(), mqConfig.getMessage());
        return "发送成功";
    }
}
